package com.css.zfzx.sjcj.modules.hddcwyGeomorphySvySamplePoint.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvySamplePoint.repository.HddcWyGeomorphysvysamplepointNativeRepository;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvySamplePoint.repository.HddcWyGeomorphysvysamplepointRepository;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvySamplePoint.repository.entity.HddcWyGeomorphysvysamplepointEntity;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvySamplePoint.service.HddcWyGeomorphysvysamplepointService;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvySamplePoint.viewobjects.HddcWyGeomorphysvysamplepointQueryParams;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvySamplePoint.viewobjects.HddcWyGeomorphysvysamplepointVO;
import com.css.bpm.platform.api.local.PlatformAPI;
import com.css.bpm.platform.sys.dict.repository.entity.DictItemEntity;
import com.css.bpm.platform.utils.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author lihelei
 * @date 2020-12-01
 */
@Service
public class HddcWyGeomorphysvysamplepointServiceImpl implements HddcWyGeomorphysvysamplepointService {

	@Autowired
    private HddcWyGeomorphysvysamplepointRepository hddcWyGeomorphysvysamplepointRepository;
    @Autowired
    private HddcWyGeomorphysvysamplepointNativeRepository hddcWyGeomorphysvysamplepointNativeRepository;

    @Override
    public JSONObject queryHddcWyGeomorphysvysamplepoints(HddcWyGeomorphysvysamplepointQueryParams queryParams ,
                                                          int curPage, int pageSize) {
        Page<HddcWyGeomorphysvysamplepointEntity> hddcWyGeomorphysvysamplepointPage =
                this.hddcWyGeomorphysvysamplepointNativeRepository.queryHddcWyGeomorphysvysamplepoints(queryParams , curPage, pageSize);
        JSONObject jsonObject = PlatformPageUtils.formatPageData(hddcWyGeomorphysvysamplepointPage);
        return jsonObject;
    }


    @Override
    public HddcWyGeomorphysvysamplepointEntity getHddcWyGeomorphysvysamplepoint(String id) {
        HddcWyGeomorphysvysamplepointEntity hddcWyGeomorphysvysamplepoint = this.hddcWyGeomorphysvysamplepointRepository.findById(id).orElse(null);
         return hddcWyGeomorphysvysamplepoint;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public HddcWyGeomorphysvysamplepointEntity saveHddcWyGeomorphysvysamplepoint(HddcWyGeomorphysvysamplepointEntity hddcWyGeomorphysvysamplepoint) {
        String uuid = UUIDGenerator.getUUID();
        hddcWyGeomorphysvysamplepoint.setId(uuid);
        hddcWyGeomorphysvysamplepoint.setCreateUser(PlatformSessionUtils.getUserId());
        hddcWyGeomorphysvysamplepoint.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        this.hddcWyGeomorphysvysamplepointRepository.save(hddcWyGeomorphysvysamplepoint);
        return hddcWyGeomorphysvysamplepoint;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public HddcWyGeomorphysvysamplepointEntity updateHddcWyGeomorphysvysamplepoint(HddcWyGeomorphysvysamplepointEntity hddcWyGeomorphysvysamplepoint) {
        hddcWyGeomorphysvysamplepoint.setUpdateUser(PlatformSessionUtils.getUserId());
        hddcWyGeomorphysvysamplepoint.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        this.hddcWyGeomorphysvysamplepointRepository.save(hddcWyGeomorphysvysamplepoint);
        return hddcWyGeomorphysvysamplepoint;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteHddcWyGeomorphysvysamplepoints(List<String> ids) {
        List<HddcWyGeomorphysvysamplepointEntity> hddcWyGeomorphysvysamplepointList = this.hddcWyGeomorphysvysamplepointRepository.findAllById(ids);
        if(!PlatformObjectUtils.isEmpty(hddcWyGeomorphysvysamplepointList) && hddcWyGeomorphysvysamplepointList.size() > 0) {
            for(HddcWyGeomorphysvysamplepointEntity hddcWyGeomorphysvysamplepoint : hddcWyGeomorphysvysamplepointList) {
                this.hddcWyGeomorphysvysamplepointRepository.delete(hddcWyGeomorphysvysamplepoint);
            }
        }
    }

    @Override
    public List<DictItemEntity> getValidDictItemsByDictCode(String dictCode) {
        List<DictItemEntity> validDictItems = PlatformAPI.getDictAPI().getValidDictItemsByDictCode(dictCode);
        return validDictItems;
    }

    @Override
    public BigInteger queryHddcWyGeomorphysvysamplepoint(HddcWyGeomorphysvysamplepointQueryParams queryParams) {
        BigInteger bigInteger = hddcWyGeomorphysvysamplepointNativeRepository.queryHddcWyGeomorphysvysamplepoint(queryParams);
        return bigInteger;
    }

}
